/**
 * Company : Thai Informatic System Co., Ltd.
 * Created By : Dr.Tree
 * Created On : May 18, 2012  12:02:16 PM 
 * e-Mail : chatree@tis.co.th
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : apps.business.process.rental.deposit_return
 * File Name : DepositReturnProcessing.java
 * TODO
 */
package apps.business.process.rental.deposit.returns;

import java.util.List;

import jpa.entitys.synchro.staging.FiApinvoicerentOutb;
import jpa.entitys.synchro.staging.FiArcnrentOutb;

import org.apache.log4j.Logger;

import promis.utility.CommonService;

import sap.business.fi.outbound.FiApinvoicerentOutbService;
import sap.business.fi.outbound.FiArcnrentOutbService;

import apps.business.process.SyncProcessorCommons;
import apps.promis.out.common.VwSyncCrnoteRentalAction;
import apps.promis.out.common.VwSyncDepositRentalReturnAction;

/**
 * @author chatree
 *
 */
public class DepositReturnProcessing extends SyncProcessorCommons{

	private static final Logger log = Logger.getLogger(DepositReturnProcessing.class);
	
	/**
	 * 
	 */
	public DepositReturnProcessing() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * 		String company = "SP"; 
			String project = "SPL_GRAND"; 
			String documentNo = "DP-1205-000002"; 
			String status = "Z";
			String syncIsstaging = "Y";
	 * @param company
	 * @param project
	 * @param documentNo
	 * @param status
	 * @param syncIsstaging
	 * @throws Exception
	 */
	public void Processing(String company, String project, String documentNo, String status, String syncIsstaging) throws Exception 
	{
		try{	
			
			//Create To Staging
			UPD_PROMISUseTime(true, false, null);
			List<FiApinvoicerentOutb> value_list = new VwSyncDepositRentalReturnAction().CreateToStaging(company, project, documentNo, status, syncIsstaging);
			UPD_PROMISUseTime(false, true, null);
			System.out.println("Create to Staging. size=" + CommonService.getSize(value_list));
			

			//Send to SAP
			if(CommonService.getSize(value_list) > 0){
				UPD_SENDUseTime(true, false, value_list.get(0).getInstanceNo());
				new FiApinvoicerentOutbService().SendToSAP(value_list);
				UPD_SENDUseTime(false, true, value_list.get(0).getInstanceNo());
			}
			System.out.println("Send to Promis. size=" + CommonService.getSize(value_list));
			
		}catch(Exception e){
			log.error(e.getMessage());
			System.err.println(e.getMessage());
			throw e;
		}
	}
	
	@Deprecated
	private void Start() throws Exception{
		
		try{
			
			VwSyncDepositRentalReturnAction obj = new VwSyncDepositRentalReturnAction();
			
			String company = "SP"; 
			String project = "SPL_GRAND"; 
			String documentNo = "DP-1205-000002"; 
			String status = "Z";
			String syncIsstaging = "Y";
			
			//Create To Staging
			List<FiApinvoicerentOutb> value_list = obj.CreateToStaging(company, project, documentNo, status, syncIsstaging);
			
			//Send to SAP
			new FiApinvoicerentOutbService().SendToSAP(value_list);
			
		}catch(Exception e){
			log.error(e.getMessage());
			System.err.println(e.getMessage());
			throw e;
		}
	}

//	/**
//	 * @param args
//	 */
//	public static void main(String[] args) {
//		// TODO Auto-generated method stub
//
//		try{
//			DepositReturnProcessing boj = new DepositReturnProcessing();
//			
//			boj.Start();
//			
//			
//		}catch(Exception e)
//		{
//			e.printStackTrace();
//			log.error(e);
//		}
//	}

}
